package com.acwing.partition14;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/4/20 9:23
 */
public class AC1351密码锁 {

    private static int[] pwd1 = new int[3], pwd2 = new int[3];
    private static int n;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt();
        for (int i = 0; i < 3; i++) pwd1[i] = nextInt();
        for (int i = 0; i < 3; i++) pwd2[i] = nextInt();
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                for (int k = 1; k <= n; k++) {
                    int[] pwd = new int[]{i, j, k};
                    if (check(pwd1, pwd) || check(pwd2, pwd)) ans++;
                }
            }
        }
        writer.println(ans);
        writer.flush();
    }

    private static boolean check(int[] pwd1, int[] pwd2) {
        for (int i = 0; i < 3; i++) {
            if (Math.abs(pwd1[i] - pwd2[i]) <= 2 || Math.abs(pwd1[i] - pwd2[i]) >= n - 2) continue;
            return false;
        }
        return true;
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
